#include "Engine.h"
#include <iostream>

#include <stdio.h>

using namespace std;

IrrPhysx *Engine::CreateIrrPhysx(Fisica *IrrFisica, Size WindowSize)
{
	irr::core::dimension2d<irr::u32> janela(WindowSize.Widht, WindowSize.Height);
	return new IrrPhysx(janela, IrrFisica);
};

Fisica *Engine::CreateFisica()
{
	NxPhysicsSDK *gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION);
	if(gPhysicsSDK == NULL)
	{
		cout << "Erro em iniciar PhysX." << endl;
		cout << "Saindo..." << endl;
		exit(1);
	}


	NxReal myTimestep = 1.0f/60.0f;

	//Cria a cena da Physx
	NxSceneDesc sceneDesc;
	sceneDesc.gravity.set(0.0f, -9.8f, 0.0f);
	sceneDesc.simType = NX_SIMULATION_SW;
	NxScene *gScene = gPhysicsSDK->createScene(sceneDesc);

	NxMaterial* defaultMaterial = gScene->getMaterialFromIndex(0);
	defaultMaterial->setRestitution(0.1);
	//defaultMaterial->setRestitution(1.0);
	defaultMaterial->setStaticFriction(0.5);
	defaultMaterial->setDynamicFriction(0.5);

	gScene->setTiming(myTimestep / 4.0f, 4, NX_TIMESTEP_FIXED);

	return new Fisica(gPhysicsSDK, gScene, myTimestep);
}
